﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XemPhim;
using System.Data;
public partial class DatPhim : System.Web.UI.Page
{
    DatPhimDao phim = new DatPhimDao();
    public void LoadKhachHang()
    {
        dlMaKhachHang.DataSource = phim.LoadMaKhachHang();
        dlMaKhachHang.DataValueField = "MaKH";
        dlMaKhachHang.DataTextField = "HoTen";
        dlMaKhachHang.DataBind();
    }
    public void LoadPhim()
    {
        dlPhim.DataSource = phim.LoadMaPhim();
        dlPhim.DataValueField = "MaPhim";
        dlPhim.DataTextField = "TenPhim";
        dlPhim.DataBind();
    }

    //public void LoadSuatChieu()
    //{
    //    dlXuatChieu.DataSource = phim.LoadMaSuatChieutest();
    //    dlXuatChieu.DataValueField = "MaSuatChieu";
    //    dlXuatChieu.DataTextField = "TenPhim";
    //    dlXuatChieu.DataBind();
    //}
    public void LoadChoNgoi()
    {
        //dlNghe.DataSource = phim.LoadChoNgoitest();
        //dlNghe.DataValueField = "MaChoNgoi";
        //dlNghe.DataTextField = "Ten";
        //dlNghe.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {


            LoadKhachHang();
            LoadPhim();
           // LoadSuatChieu();
            LoadChoNgoi();
            lisGhe.DataSource = phim.LoadChoNgoitest();
            lisGhe.DataTextField = "Ten";
            lisGhe.DataValueField = "MaChoNgoi";
            lisGhe.DataBind();
        }
    }

    

    protected void dlPhim_SelectedIndexChanged(object sender, EventArgs e)
    {


        dlXuatChieu.DataSource = phim.LoadMaSuatChieutest(int.Parse(dlPhim.SelectedValue.ToString()));
        dlXuatChieu.DataTextField = "NgayChieu";
        dlXuatChieu.DataValueField = "MaSuatChieu";
        dlXuatChieu.DataBind();
       
    }
    protected void bt_datve_Click(object sender, EventArgs e)
    {
      
        DataTable data = phim.sp_ThemHoaDon(int.Parse(dlMaKhachHang.SelectedValue.ToString()), DateTime.Today, 0);
        DataRow dr = data.Rows[0];
        int MaHoaDon = int.Parse(dr["MaHoaDon"].ToString());
        foreach (ListItem item in lisGhe.Items)
        {
            if (item.Selected)
            {
                Response.Write(MaHoaDon);
                phim.DatVe(MaHoaDon, int.Parse(dlXuatChieu.SelectedValue.ToString()), 1, int.Parse(item.Value.ToString()));
                 
            }
        }
    }
    protected void lisGhe_SelectedIndexChanged(object sender, EventArgs e)
    {
       
   

    }
    protected void dlNghe_SelectedIndexChanged(object sender, EventArgs e)
    {
       // Label1.Text = dlNghe.SelectedValue.ToString();
    }
    protected void dlXuatChieu_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}